package com.mes.web.controller.cb;

import com.mes.entity.cb.MaMove;
import com.mes.entity.cb.Pages;
import com.mes.entity.hy.Maters;
import com.mes.service.cb.MaMoveService;
import com.mes.utils.CustomUtils;
import com.mes.utils.DateJsonValueProcessor;
import com.mes.utils.ResponseUtil;
import com.mes.utils.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName: MaMoveController
 * @Description: 资材移库
 * @Author cb
 * @Date 2018年4月12日15:53:12
 * @version 1.0
 */
@Controller
@RequestMapping("/move")
public class MaMoveController {

    @Resource
    private MaMoveService maMoveService;

    @RequestMapping("/MaMove_list")
    public void MaMove_list(HttpServletResponse response, String limit, String offset,String num) throws Exception {
        Pages pages = CustomUtils.pagings(limit, offset);

        if (StringUtil.isNotEmpty(num)) {
            pages.setNumber(num);
        }

        List<Maters> list = maMoveService.MaMove_list(pages);
        int getTotal = maMoveService.MaMove_listTotal(pages);

        JSONObject jsonObject = new JSONObject();
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
        JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
        jsonObject.put("total", getTotal);
        jsonObject.put("rows", jsonArray);
        ResponseUtil.write(response, jsonObject);

    }

    @RequestMapping("/MaMoveMx_list")
    public void MaMoveMx_list(HttpServletResponse response, String limit, String offset,long mid) throws Exception {
        Pages pages = CustomUtils.pagings(limit, offset);
        pages.setRid(mid);
        List<MaMove> list =  maMoveService.MaMoveMx_list(pages);

        int getTotal = maMoveService.MaMoveMx_listTotal(pages);

        JSONObject jsonObject = new JSONObject();
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
        JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
        jsonObject.put("total", getTotal);
        jsonObject.put("rows", jsonArray);
        ResponseUtil.write(response, jsonObject);

    }

    @RequestMapping("/MaMove_sum")
    @ResponseBody
    public int MaMove_sum(String pickOdd) {
        int total = maMoveService.MaMove_sum(pickOdd);

        return total;
    }

}
